#include <stdio.h>

int main ()
{

    int n ;

    scanf ("%d" , &n) ;

    int array [3] [2] ;

    for (int j = 0 ; j < 3 ; j++)
    {

        for (int k = 0 ; k < 2 ; k++)
        {

            scanf("%d" , &array [j] [k]) ;

        }

    }

    for (int i = 0 ; i < 3 ; i++)
    {

        if (n % array [i] [0] != 0)
        {

            array [i] [1] *= ((n / array [i] [0]) + 1) ;

        }

        else
        {

            array [i] [1] *= (n / array [i] [0]) ;

        }

    }

    n = array [0] [1] ;

    for (int i = 1 ; i < 3 ; i++)
    {

        if (array [i] [1] < n)
        {

            n = array [i] [1] ;

        }

    }
    
    printf("%d" , n) ;

    return 0 ;

}